Skip to content

Fix UninitializedPropertyAccessException#3542

Merged
andreia-ferreira merged 4 commits intomasterfrom
andreia/3517/fix-vm-not-initialized
Feb 12, 2026
Merged

Fix UninitializedPropertyAccessException#3542
andreia-ferreira merged 4 commits intomasterfrom
andreia/3517/fix-vm-not-initialized

Conversation

@andreia-ferreira
Copy link
Collaborator

@andreia-ferreira andreia-ferreira commented Feb 11, 2026

Fixes #3517
The task VM was initialized in onViewCreated, but PhotoTaskFragment, for example, registers its capturePhotoLauncher in onCreate. If the activity result fired before the view attached (e.g. after process death while the camera was open), the VM would be uninitialized, causing the UninitializedPropertyAccessException.

This PR moves the task VM initialization to by lazy. This should should be safe since the taskId is available at that point (set by either the parent adapter or restored from the saved instance) and if the task fragment is initalized it means that the data collection VM is also on a ready state.

before:

Screen_recording_20260211_182658.webm

after:

Screen_recording_20260211_182439.webm

@shobhitagarwal1612 PTAL?

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @andreia-ferreira, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug where the task ViewModel could be uninitialized, leading to a crash, especially in scenarios involving process death and activity results. By shifting the ViewModel's initialization to an earlier lifecycle stage, onCreate, the change ensures that the ViewModel is consistently available when needed, improving the application's robustness and user experience.

Highlights

  • Fix UninitializedPropertyAccessException: Resolved an UninitializedPropertyAccessException that occurred when the task VM was not initialized before an activity result fired, particularly after process death while the camera was open.
  • ViewModel Initialization Timing: Moved the task ViewModel initialization from onViewCreated to onCreate to ensure the ViewModel is ready earlier in the fragment lifecycle.
  • Code Cleanup: Removed the isViewModelInitialized property and associated Timber import, simplifying the ViewModel access logic.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • app/src/main/java/org/groundplatform/android/ui/datacollection/tasks/AbstractTaskFragment.kt
    • Removed the Timber import statement.
    • Deleted the isViewModelInitialized computed property.
    • Relocated the ViewModel initialization logic from onViewCreated to onCreate.
    • Removed the conditional check for isViewModelInitialized before calling onTaskResume() in the onResume method.
Activity
  • The author provided screen recordings demonstrating the bug before the fix and the correct behavior after the fix.
  • The author requested a review from @shobhitagarwal1612.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively addresses an UninitializedPropertyAccessException by moving the TaskViewModel initialization from onViewCreated to onCreate. This ensures the ViewModel is available earlier in the fragment's lifecycle, preventing crashes when activity results are delivered before the view is created. The changes are logical and correctly remove the now-redundant isViewModelInitialized property and its related checks. I have one minor suggestion for code conciseness.

@codecov
Copy link

codecov bot commented Feb 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.62%. Comparing base (8305387) to head (ff24fd0).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##             master    #3542   +/-   ##
=========================================
  Coverage     70.62%   70.62%           
  Complexity     1621     1621           
=========================================
  Files           327      327           
  Lines          8889     8889           
  Branches        982      982           
=========================================
  Hits           6278     6278           
  Misses         2023     2023           
  Partials        588      588           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@andreia-ferreira andreia-ferreira merged commit da0c6c4 into master Feb 12, 2026
9 checks passed
@andreia-ferreira andreia-ferreira deleted the andreia/3517/fix-vm-not-initialized branch February 12, 2026 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Trending crash] UninitializedPropertyAccessException: lateinit property viewModel has not been initialized

2 participants